package cmd

import (
	"errors"
	"fmt"
	"gitee.com/cobra-demon/cmd/config"
	"gitee.com/cobra-demon/cmd/version"
	"github.com/spf13/cobra"
	"os"
)

var rootCmd = &cobra.Command{
	Use: "cobra",
	Short: "cobra",
	SilenceUsage: true,
	Long: "go-cobra",
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args)<1 {
			return errors.New("args lenth <=0")
		}
		return nil
	},
	Run: func(cmd *cobra.Command, args []string) {
		help()
	},
}

func init() {
	rootCmd.AddCommand(config.ConfigCmd)
	rootCmd.AddCommand(version.VersionCmd)
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		os.Exit(-1)
	}
}

func help()  {
	fmt.Println("--help 查看命令")
}